package com.XinYun.Library.utils.HTTPRequestUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;

public class HTTPRequestUtil {
    /**
     * 获得请求体
     * @param request
     * @return 请求体字符串
     * @throws IOException
     */
    public static String getBody(HttpServletRequest request) throws IOException {
        // 获取请求体
        BufferedReader br = request.getReader();
        String inputLine;
        StringBuffer str = new StringBuffer();
        try {
            while ((inputLine = br.readLine()) != null) {
                str.append(inputLine);
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str.toString();
    }
}
